#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5+5;
int n, m, a[N], b[N];
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin >> n >> m;
	for (int i=1; i<=n; ++i)
	{
		cin >> a[i];
	}
	for (int i=1; i<=m; ++i)
	{
		cin >> b[i];
	}
	int ans=0;
	for (int i=1; i<n; i++)
	{
		ans += abs(a[i+1]-a[i]);
	}
	for (int i=1; i<m; i++)
	{
		ans += abs(b[i+1]-b[i]);
	}
	cout << ans << endl;
	return 0;
}
